package com.maxjay.system.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DictTab implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3904306472852095900L;
	
	public static final String ID_FIELD = "ID";
	public static final String TAB_CODE_FIELD = "TAB_CODE";
	public static final String TAB_NAME_FIELD = "TAB_NAME";
	public static final String TAB_DESC_FIELD = "TAB_DESC";
	public static final String TAB_TYPE_FIELD = "TAB_TYPE";
	public static final String NAME_FIELD_FIELD = "NAME_FIELD";
	public static final String CODE_FIELD_FIELD = "CODE_FIELD";
	
	public static final String NORMAL_DICT_TAB = "01";
	public static final String ISOMERISM_DICT_TAB = "02";
	
	private String id;
	private String tabCode;
	private String tabName;
	private String tabDesc;
	
	/**
	 * 字典表类型，01 正规字典表，02 异构字典表
	 */
	private String tabType;
	private String nameField;
	private String codeField;
	
	private Map<String, DictCode> dictCodeMap = new HashMap<String, DictCode>(0);
	
	public String getDictName(String code) {
		DictCode dictCode = dictCodeMap.get(code);
		if (dictCode != null) {
			return dictCode.getName();
		} else {
			return code;
		}
	}
	
	public String getDictCode(String name) {
		for (Map.Entry<String, DictCode> entry : dictCodeMap.entrySet()) {
			DictCode dictCode = entry.getValue();
			if (dictCode.getName().equals(name)) {
				return dictCode.getCode();
			}
		}
		return null;
	}
	
	public void addDictCode(DictCode dictCode) {
		this.dictCodeMap.put(dictCode.getCode(), dictCode);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTabCode() {
		return tabCode;
	}

	public void setTabCode(String tabCode) {
		this.tabCode = tabCode;
	}

	public String getTabName() {
		return tabName;
	}

	public void setTabName(String tabName) {
		this.tabName = tabName;
	}

	public String getTabDesc() {
		return tabDesc;
	}

	public void setTabDesc(String tabDesc) {
		this.tabDesc = tabDesc;
	}

	public String getTabType() {
		return tabType;
	}

	public void setTabType(String tabType) {
		this.tabType = tabType;
	}

	public List<DictCode> getDictCodes() {
		List<DictCode> dictCodes = new ArrayList<DictCode>();
		for (Map.Entry<String, DictCode> entry : dictCodeMap.entrySet()) {
			dictCodes.add(entry.getValue());
		}
		return dictCodes;
	}

	public void setDictCodes(List<DictCode> dictCodes) {
		for (DictCode dictCode : dictCodes) {
			dictCodeMap.put(dictCode.getCode(), dictCode);
		}
	}

	public String getNameField() {
		return nameField;
	}

	public void setNameField(String nameField) {
		this.nameField = nameField;
	}

	public String getCodeField() {
		return codeField;
	}

	public void setCodeField(String codeField) {
		this.codeField = codeField;
	}

}
